<?php

/**
 * 配置信息获取/保存
 * @return [type] [description]
 */
function WebConfig($type='',$data=array()){ 
	$Model  = M('config'); 
	if(empty($data)){
		$config = F($type, '', TEMP_PATH); 
		if(empty($config)){
			$where['type'] = $type;
			$info = $Model->where($where)->select();
			if($info){
				foreach($info as $k => $v){
					$result[$v['name']] = $v['value'];
				}
				return F($type, $result, TEMP_PATH);
			}
		}
		return $config;
	}else{
		//查出所有的
		$find = $Model->where('type='.$type)->select();
		if($find){
			foreach($find as $value){
				$temp[$value['name']] = $value['value'];
			}
			foreach($data as $k => $v){
				$checkData = array('name'=>$k,'value'=>$v,'type'=>$type);
				//存在 更新
				if(isset($temp[$k])){
					#与数据库记录不等时，更新
					if($v != $temp[$k]){
						$Model->where("name=".$k)->save($checkData);
					}
				}else{
					$Model->add($checkData);
				}
			}
			//重新获取更新后的数据
			$select = $model->where('type='.$type)->select();
			foreach($select as $val){
				$result[$val['name']] = $val['value'];
			}
		}else{
			foreach($data as $k => $v){
				$checkData[] = array('name'=>$k,'value'=>$v,'type'=>$type);
			}
			$model->addAll($checkData);
			$newData = $data;
		}
		return F($type, $newData, TEMP_PATH);
	}
	
	/**
     * 获取导航
     */
	function getAdminMenu(){
	    return array(
	         'System'=>array(
	         	'name'=>'系统',
	         	'son'=>array(
	         		array('name'=>'站点配置','controller'=>'System','action'=>'index'),
	         	),
	         ),
	         'Contents'=>array(
	         	'name'=>'内容',
	         	'son'=>array(
	         		array('name'=>'文章列表','controller'=>'Article','action'=>'index'),
	         		array('name'=>'文章分类','controller'=>'Article','action'=>'classify'),
	         		array('name'=>'公告列表','controller'=>'Notice','action'=>'index'),
	         		array('name'=>'公告分类','controller'=>'Notice','action'=>'classify'),
	         		array('name'=>'产品列表','controller'=>'Product','action'=>'index'),
	         		array('name'=>'产品分类','controller'=>'Product','action'=>'classify'),
	         		array('name'=>'单页管理','controller'=>'Single','action'=>'index'),
	         		array('name'=>'广告列表','controller'=>'Banner','action'=>'index'),
	         		array('name'=>'广告位置','controller'=>'Banner','action'=>'position'),
	         	),
	         ),
	         'Member'=>array(
	         	'name'=>'用户',
	         	'son'=>array(
	         		array('name'=>'管理员','controller'=>'Admin','action'=>'index'),
	         		array('name'=>'管理员角色','controller'=>'Admin','action'=>'role'),
	         		array('name'=>'管理员日志','controller'=>'Admin','action'=>'log'),
	         		array('name'=>'会员','controller'=>'Member','action'=>'index'),
	         		array('name'=>'会员等级','controller'=>'Member','action'=>'level'), 
	         	),
	         ),
	        
        );
    }
	
	
	
}
?>